package com.itheima.service.ServiceImpl;

import com.itheima.service.PetBranchService;
import com.itheima.mapper.PetBranchMapper;
import com.itheima.pojo.Branch;
import com.itheima.utils.UserThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class PetBranchServiceImpl implements PetBranchService {

    @Autowired
    private PetBranchMapper petBranchMapper;

    //添加门店
    @Override
    public void addBranch(Branch branch) {
        branch.setCreateTime(LocalDateTime.now());
        branch.setUpdateTime(LocalDateTime.now());
        petBranchMapper.saveBranch(branch);
    }

    //删除门店
    @Override
    public void deleteBranch(Integer id) {
        petBranchMapper.deleteBranch(id);
    }

    //修改门店
    @Override
    public void updateBranch(Branch branch) {
        branch.setUpdateTime(LocalDateTime.now());
        petBranchMapper.updateBranch(branch);
    }

    //查询门店(根据ID查询门店)
    @Override
    public Branch getInfo(Integer id) {

        //调用通过id查询门店方法
        Branch branch = petBranchMapper.getById(id);
        return branch;
    }

    //门店列表查询
    @Override
    public List<Branch> getBranchList() {
        List<Branch> branchs = petBranchMapper.queryBranch();
        return branchs;
    }
}
